package com.qidi.service.impl;

import com.qidi.bean.Employee;
import com.qidi.bean.EmployeeExample;
import com.qidi.dao.EmployeeMapper;
import com.qidi.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhouXinBin
 * @create 2020-10-26-12:02
 */
@Service
public class EmployeeServiceimpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public List<Employee> getAllEmp() {
        List<Employee> employees = employeeMapper.selectByExampleWithDept(null);
        return employees;
    }

    @Override
    public void saveEmp(Employee employee) {
        employeeMapper.insertSelective(employee);
    }

    @Override
    public boolean checkEmpName(String empName) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        long count = employeeMapper.countByExample(example);
        return count==0;
    }

    @Override
    public Employee getEmpById(Integer empId) {
        Employee employee = employeeMapper.selectByPrimaryKey(empId);
        return employee;
    }

    @Override
    public void updateEmp(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

    @Override
    public void deletEmpById(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteBatchEmps(List<Integer> batchIds) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpIdIn(batchIds);
        employeeMapper.deleteByExample(example);
    }

    @Override
    public List<Employee> getEmpsByName(String empName) {
        List<Employee> list = employeeMapper.selectByValWithDept(empName);
        return list;
    }

}
